import React, { Component } from 'react'
import './index.css'
export default class Footer extends Component {
  changeAll = (e) => {
    this.props.changeAll(e.target.checked)
  }
  render() {
    const { toDoList } = this.props
    const total = toDoList.length
    const doneNum = toDoList.reduce((pre, item) => {
      return pre + (item.done ? 1 : 0)
    }, 0)
    return (
      <div className="todo-footer">
        <label>
          <input
            type="checkbox"
            checked={doneNum === total && total !== 0 ? true : false}
            onChange={this.changeAll}
          />
        </label>
        <span>
          <span>已完成{doneNum}</span> / 全部{total}
        </span>
        <button className="btn btn-danger" onClick={this.props.clearDone}>
          清除已完成任务
        </button>
      </div>
    )
  }
}
